﻿<?php
class ProductAction extends GlobalAction
{
   
    public function index()
    {
        import("ORG.Util.Page");
		self::pub_part();
		$keyword = $_REQUEST['keyword'];
		$condition ='';
		if($keyword != ''){$condition .= "title like '\%$keyword\%' and ";}
        $condition .=' 1=1';
		$dao = M('products');
		$total = $dao->where($condition)->count();
        $page = new Page($total,10);
         $list=$dao->where($condition)->limit($page->firstRow.",".$page->listRows)->select();	
		 foreach($list as $k=>$v){
		$list[$k]['company_name'] = parent::_get_field('company','id='.$v['company_id'],'company_name');
		$list[$k]['url'] ="/show_product/".$v['company_id'].'-'.$v['id'].'.html';
		$list[$k]['product_class'] = parent::_get_field('product_class','id='.$v['pro_class'],'class_name');
			 }
         $show = $page ->show();
		 $this->assign('list',$list);
		 
	
		 $this -> assign('page',$show); // 赋值分页输出
		 //dump($list);
        $this->display();
    }

function pub_part(){
		//平台帮助
		$list_rec_help = parent::rec_help();
		$this->assign('list_rec_help',$list_rec_help);
		//热门产品
		
		$list_hot = self::hot_news(10,'hot');
		 $this->assign('list_hot',$list_hot);
		 //推荐公司
		$list_rec_company = parent::rec_company();
		$this->assign('list_rec_company',$list_rec_company);
		}

function hot_news($num=10,$type){
	
	if($type =='hot')
	{
		$orders ='t_tuijian desc';
	}
	elseif($type =='new')
	{
		$orders ='id desc';
	}
	else
	{
		$orders ='';
	}
	$list = M('products')->order($orders)->limit($num)->select();
	return $list;
	}

}
?>